//
//  SQLowAuctionViewCell.m
//  pai
//
//  Created by pro on 14-11-7.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import "SQLowAuctionViewCell.h"
#import "ASIHTTPRequest.h"
#import "UIImageView+WebCache.h"
#import "Global.h"

@implementation SQLowAuctionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"SQLowAuctionViewCell" owner:self options: nil];
        if(arrayOfViews.count < 1){return nil;}
        if(![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]){
            return nil;
        }
        self = [arrayOfViews objectAtIndex:0];
    }
    return self;
}

-(void)setDic:(NSDictionary *)dic
{
    
}
-(void)setItem:(auct_sku_item_t)item
{
    _serialnum = [NSString stringWithUTF8String:item.serialnum];
    
    //UIImage *image = [UIImage imageNamed:@"img01"];
    //self.imageView.image = image;
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    [dateFormatter setDateFormat:@"MM-dd HH:mm:ss"];
    
    NSDate* start = [NSDate dateWithTimeIntervalSince1970:item.stdate];
    NSDate* end = [NSDate dateWithTimeIntervalSince1970:item.eddate];
    
    NSString *strDate = [dateFormatter stringFromDate:start];
    NSString *endDate = [dateFormatter stringFromDate:end];
    
    [self.nameLabel setText:[NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:item.sku_name]]];
    [self.timeLabel setText:[NSString stringWithFormat:@"%@开始竞拍",strDate]];
    NSLog(@"%s",item.sku_code);
    
    //if (self.imageUrl == nil) {
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/skus/%@/photos.json", IMAGESERVICE,[NSString stringWithUTF8String: item.sku_code]]];
        NSLog(@"get image url:%@",url);
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        
        [request startSynchronous];
        
        NSError *error = [request error];
        
        if (!error) {
            
            NSString *response = [request responseString];
            NSLog(@"%@",response);
            
            NSData *data= [response dataUsingEncoding:NSUTF8StringEncoding];
            NSError *error = nil;
            NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
            //        NSLog(@"%@",dic);
            //        NSLog(@"home:%@",[dic objectForKey:@"home"]);
            //        NSMutableArray* array =[dic objectForKey:@"intro"];
            //        NSLog(@"count:%d",array.count);
            NSString* imageUrl = [NSString stringWithFormat:@"%@%@",IMAGESERVICE,[dic objectForKey:@"home"]];
            self.imageDic = dic;
            self.imageUrl =imageUrl;
        }
    //}
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.imageView setImageWithURL:[NSURL URLWithString:self.imageUrl] placeholderImage:nil];
    
}
-(void)onnameLabel:(UILabel*)label
{
    NSLog(@"124234234");
    NSLog(@"%@",label.text);
}

@end
